package Touchy;

/**
 * Touchy!
 * 
 * Interactive learing tool to increase typing speed.
 * 
 * This class handles gamesates, and is the class that hold the different state panels.
 * 
 * @author Sletten
 */

import java.awt.Dimension;

import project.LearningTool;
import project.V12;

public class Touchy extends LearningTool
{	
	private MenuPanel mMenuPanel;
	private GamePanel mGamePanel;
	private EndGamePanel mEndGamePanel;

	private int mState;
	public final int MENU = 1;
	public final int GAME = 2;
	public final int ENDGAME = 3;
	/**
	 * Constructor
	 */
	public Touchy()
	{
		super();
		mToolPanel.setLayout(null);
		mToolPanel.setPreferredSize(new Dimension(800,600));
		
		mMenuPanel = new MenuPanel(this);
		mMenuPanel.setBounds(0, 0, 800, 600);
		mGamePanel = new GamePanel(this);
		mGamePanel.setBounds(0, 0, 800, 600);
		mEndGamePanel = new EndGamePanel(this);
		mEndGamePanel.setBounds(0, 0, 800, 600);
		
		setState(MENU);
	}
	public void setState(int inState)
	{
		mState = inState;
		switch (mState)
		{
		case MENU:
			mToolPanel.removeAll();
			mToolPanel.add(mMenuPanel);
			break;
		case GAME:
			mToolPanel.removeAll();
			mToolPanel.add(mGamePanel);
			break;
		case ENDGAME:
			mToolPanel.removeAll();
			mToolPanel.add(mEndGamePanel);
			break;
		}
		
		mToolPanel.repaint();
		V12.getInstance().update();
	}
	public void run()
	{
		boolean done = false;
		while (!done)
		{
			switch (mState)
			{
			case MENU:
				mMenuPanel.run();
				break;
			case GAME:
				mGamePanel.run();
				break;
			case ENDGAME:
				mEndGamePanel.run();
				break;
			}
			// frees up some processor power by calling sleep
			Timer.updateTimer();
		}
	}
	
	//used to pass along score to the endgame panel
	public EndGamePanel getEndGame()
	{
		return mEndGamePanel;
	}
}
